<template>
	<el-select v-model="projName" filterable :filter-method="filterChoose" value-key="projId" placeholder="请选择项目" @change="projChoose">
	    <el-option
	      v-for="item in projectList"
	      :key="item.projId"
	      :label="item.name"
	      :value="item">
	    </el-option>
	  </el-select>
</template>

<script>
	import {
		list
	} from '@/api/project'
	export default {
		data() {
			return {
				projectList: [],
				listQuery:{
					current:1,
					size:20,
					name:''
				},
				projName:''
			};
		},
		props:['name'],
		watch: {
			name(newval,oldval){
				this.projName = newval
			}
		},
		created() {
			this.listclick()
			this.projName=this.name
		},
		methods: {
			listclick() {
				var _this = this
				list(_this.listQuery,false).then(res => {
					this.projectList = res.data.records
				})
			},
			projChoose(data){
				this.projName = data.name
				this.$emit('projectSelect',data)
			},
			filterChoose(data){
				var _this = this
				if (this.timer) {
					clearTimeout(this.timer);
				}
				this.timer = setTimeout(() => {
					_this.listQuery.name = data
					_this.listclick()
				}, 500);
			}
		}
	};
</script>

<style>
</style>
